// 全部商品分类
var category_list = document.querySelectorAll(".category-list"),
  commodity = document.querySelectorAll(".commodity");
for (var i = 0; i < category_list.length; i++) {
  category_list[i].index = i;
  category_list[i].onmouseover = function () {
    for (var i = 0; i < commodity.length; i++) {
      commodity[i].style.display = "none";
    }
    commodity[this.index].style.display = "block";
    category_list[this.index].classList.add("listBcolor");
  };
  category_list[i].onmouseout = function () {
    category_list[this.index].classList.remove("listBcolor");
    commodity[this.index].style.display = "none";
  };
}

async function num_jian(pid, ipt) {
  console.log(pid);
  for (let i = 0; i < num_jias.length; i++) {
    num_jias[i].onclick = function () {
      input_nums[i].value = Number(input_nums[i].value) + 1;
      let updateCartNumAPI =
        "http://jx.xuzhixiang.top/ap/api/cart-update-num.php";
      let pnum = input_nums[i].value;
      let uid = localStorage.getItem("id");
      let params = { pnum, pid, uid };
      console.log(params);
      let rres = axios.get(updateCartNumAPI, { params });
      console.log(rres.data);
      LoadCartList();
      console.log(input_nums[i].value);
    };
  }
}

$(function () {
  //1.移入出现btn
  $(".item").hover(
    function () {
      $(this).find(".item-btn").stop().animate(
        {
          "margin-top": -25,
        },
        300
      );
    },
    function () {
      $(this).find(".item-btn").stop().animate(
        {
          "margin-top": 28,
        },
        300
      );
    }
  );
});

function num_jia(pid, ipt) {
  console.log(pid);
  console.log(ipt);
  input_nums = document.querySelectorAll(".goods-num");
  num_jias = document.querySelectorAll(".fa-plus");
  for (let i = 0; i < num_jias.length; i++) {
    num_jias[i].onclick = async function () {
      input_nums[i].value = Number(input_nums[i].value) + 1;
      let updateCartNumAPI =
        "http://jx.xuzhixiang.top/ap/api/cart-update-num.php";
      let pnum = input_nums[i].value;
      let uid = localStorage.getItem("id");
      let params = { pnum, pid, uid };
      console.log(params);
      let res = await axios.get(updateCartNumAPI, { params });
      console.log(res.data);
      console.log(input_nums[i].value);
      LoadCartList();
    };
  }
}
function num_jia(pid, ipt) {
  console.log(pid);
  console.log(ipt);
  input_nums = document.querySelectorAll(".goods-num");
  num_jias = document.querySelectorAll(".fa-plus").next;
  for (let i = 0; i < num_jias.length; i++) {
    num_jias[i].onclick = async function () {
      input_nums[i].value = Number(input_nums[i].value) + 1;
      let updateCartNumAPI =
        "http://jx.xuzhixiang.top/ap/api/cart-update-num.php";
      let pnum = input_nums[i].value;
      let uid = localStorage.getItem("id");
      let params = { pnum, pid, uid };
      console.log(params);
      let res = await axios.get(updateCartNumAPI, { params });
      console.log(res.data);
      console.log(input_nums[i].value);
      LoadCartList();
    };
  }
}
function getsum() {
  var count = 0;
  $(".shuru").each(function (i, ele) {
    count += parseInt($(ele).val());
    console.log(count);
  });
  let totaprice = 0;
  $(".chk:checked").each(function () {
    totaprice += Number($(this).parent().siblings(".pprice").text());
  });
  $(".pprice2").text(totaprice);
}
